package com.yanqu.road.dao.impl.activity.snowgarden;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.snowgarden.config.SnowGardenStatueConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SnowGardenStatueConfigDaoImpl extends TempDao {

    private static String getSnowGardenStatueConfigSql = "select * from `t_s_activity_snowgarden_statue` where `activityId`=?";

    public Map<Integer, SnowGardenStatueConfig> getSnowGardenStatueConfig(int activityId){
        Map<Integer, SnowGardenStatueConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getSnowGardenStatueConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SnowGardenStatueConfig snowGardenStatueConfig = new SnowGardenStatueConfig();
                snowGardenStatueConfig.setActivityId(rs.getInt("activityId"));
                int id = rs.getInt("id");
                snowGardenStatueConfig.setId(id);
                snowGardenStatueConfig.setName(rs.getString("name"));
                snowGardenStatueConfig.setDesc(rs.getString("desc"));
                snowGardenStatueConfig.setScore(rs.getInt("score"));
                snowGardenStatueConfig.setBackGround(rs.getInt("background"));
                map.put(id, snowGardenStatueConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }
}
